﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

using Redboil.Bfp.Core;

namespace Redboil.Practices.Mvc3 {
    public class Global : System.Web.HttpApplication {
        private Container container;

        public static void RegisterGlobalFilters(GlobalFilterCollection filters) {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes) {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //URL地址的第一部分决定调用哪个控制器类，所以“/HelloWorld”映射到HelloWorldController控制器类。第二部分决定调用控制器中的哪个方法。所以“/HelloWorld/Index”将会调用HelloWorldController控制器类的Index方法。由于Index方法是控制器类的默认方法（可以另外指定控制器类的默认方法），所以也可只输入“/HelloWorld”来调用该方法。
            //routes.MapRoute("Authentication.Validate", "Authentication/Validate", new { controller = "Authentication", action = "Validate" });
            //routes.MapRoute("Authorization", "Authorization/{action}/{id}", new { controller = "Authorization" });
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{paramaters}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start() {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}